<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>点击变色</title>
    <script src="../vue2.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }

        ul li {
            list-style: none;
        }

        ul{
            font-size: 40px;
            height: 100px;
            display: flex;
        }

        ul li{
            height: 100%;
            line-height: 100px;
            flex: 1;
            text-align: center;
        }

        .active {
            background-color: skyblue;
        }

    </style>
</head>
<body>
<div id="box">
    <ul>
        <li v-for="(data,index) in dataList" @click="handleColor(index)" :class="backcolorIndex===index?'active':''">
            {{data}}
        </li>
    </ul>
</div>
<script>
    new Vue({
        el: '#box',
        data: {
            dataList: ['首页', '动态', '我的'],
            backcolorIndex: 0,
        },
        methods: {
            handleColor(index) {
                this.backcolorIndex = index
            }
        }
    })
</script>
</body>
</html>